<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>

    <div id="app">
        <h3>Ref</h3>
        <div ref="box">
            我是div盒子 --- {{ count }}
            <button @click="addFn">点我</button>
        </div>
        <com ref="com"/>
    </div>

    <template id="com">
        <div>
            <h3>我是一个组件 --- {{ count }}</h3>
        </div>
    </template>

    <script src="./js/vue.js"></script>
    <script>
        // Ref 
        // 1. 给标签上加 ==>  真实的dom节点
        // 2. 给组件加 ==>  组件实例

        const Com = {
            template: "#com",
            data() {
                return {
                    count: 888888
                }
            },
            methods: {
                add() {
                    this.count += 1
                }
            }
        }

        new Vue({
            el: "#app",
            data() {
                return {
                    count: null
                }
            },
            // dom结构挂载完成
            mounted() {
                console.log(this.$refs)
                this.count = this.$refs.com.count
                // this.$refs.box.innerHTML = "我修改了"
            },
            methods: {
                addFn() {
                    this.$refs.com.add()
                }
            },
            components: {
                Com
            }
        })
    </script>
</body>
</html>